package com.cskaoyan;


import com.mysql.jdbc.Driver;

import java.sql.*;

/**
 * 创建日期: 2022/11/22 11:22
 *
 * @author ciggar
 */
public class JDBCMain {

    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        // 注册驱动
        DriverManager.registerDriver(new Driver());
//        Class.forName("com.mysql.jdbc.Driver");


        // 获取连接
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/46th?useSSL=false&characterEncoding=utf8",
                "root",
                "123456"
        );


        // 获取statement对象
        Statement statement = connection.createStatement();

        // 发送SQL语句
        ResultSet resultSet = statement.executeQuery("select * from account where id = 1001");


        // 解析结果集
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");

            System.out.println("id:" + id + ",name:" + name);
        }

        // 关闭资源
        resultSet.close();
        statement.close();
        connection.close();

    }


}
